# -*- encoding:utf-8 -*-
'''
	usedao.py
	======================
	@descript: 
	@copyright:chinasoft
	@author:cjgong
	@date: 2021-03-04 10:02
	@version:v1.0
'''
from app01.pymysqlutil import PyMysqlUtil
from app01.user import User


class UserDao:
    @staticmethod
    def f_select_user():
        # UserDao.v_log.debug('f_select_user开始执行……')
        v_result = []
        var_psyMysqlUtil = PyMysqlUtil()
        with var_psyMysqlUtil  as  var_cursor:
            var_sql = 'SELECT django02.`user_id`,django02.`user_name`,django02.`user_sex`,django02.`user_height`,django02.`tel` FROM django02;'
            var_cursor.execute(var_sql)
            var_resultset02 = var_cursor.fetchall()
            for element in var_resultset02:
                # print(element)
                from app01.user import User
                v_user = User(**element)
                v_result.append(v_user)
                pass
            pass
        # UserDao.v_log.debug('f_select_user执行结束……')
        return v_result

    @classmethod
    def f_delete_user(cls, p_user_id):
        # UserDao.v_log.debug('f_delete_user开始执行……')
        var_psyMysqlUtil = PyMysqlUtil()
        with var_psyMysqlUtil  as  var_cursor:
            var_sql = 'DELETE FROM django02 WHERE django02.`user_id`=%s;'
            var_cursor.execute(var_sql, (p_user_id,))
            pass
        # UserDao.v_log.debug('f_delete_user执行结束……')

    @classmethod
    def f_insert_user(cls, p_user: User):
        # UserDao.v_log.debug('f_insert_user开始执行……')
        var_psyMysqlUtil = PyMysqlUtil()
        with var_psyMysqlUtil  as  var_cursor:
            var_sql = 'INSERT INTO django02(django02.`user_name`,django02.`user_sex`,django02.`user_height`,django02.`tel`) VALUE(%s,%s,%s,%s);'
            var_cursor.execute(var_sql, (p_user.v_user_name, p_user.v_user_sex, p_user.v_user_height, p_user.v_tel))
        pass
        # UserDao.v_log.debug('f_insert_user执行结束……')


    pass